﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchoolLibrary.Entity;
using SchoolLibrary.DataBase.DAO;
using SchoolLibrary.Desktop.Guide.Input;

namespace SchoolLibrary.Desktop.Guide
{
    public class ClassGuideForm : GuideForm<Class>
    {

        private string[] COLUMN_NAMES = { "id", "Номер", "Литера", "Классный руководитель" };

        public ClassGuideForm() : base() { }

        protected override void addButton_Click(object sender, EventArgs e)
        {
            ClassInputDialog dialog = new ClassInputDialog();
            dialog.ShowDialog();
            Class pupilClass = dialog.Class;
            if (pupilClass != null)
            {
                ClassDAO.getInstance().save(pupilClass);
                this.initData();
            }
        }

        protected override void editButton_Click(object sender, EventArgs e)
        {
            long id = getSelectedRowId();
            Class selectedClass = ClassDAO.getInstance().findById(id);
            ClassInputDialog dialog = new ClassInputDialog(selectedClass);
            dialog.ShowDialog();
            Class pupilClass = dialog.Class;
            if (pupilClass != null)
            ClassDAO.getInstance().save(pupilClass);
            this.initData();
        }

        protected override void deleteButton_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override string[] getColumnNames()
        {
            return COLUMN_NAMES;
        }

        protected override List<Class> findAll()
        {
            return ClassDAO.getInstance().findAll();
        }

        protected override Class findById(long id)
        {
            return ClassDAO.getInstance().findById(id);
        }

        protected override object[] createRow(Class value)
        {
            List<object> row = new List<object>();
            row.Add(value.Id);
            row.Add(value.Number);
            row.Add(value.Letter);
            row.Add(value.ClassLeader.AbbreviatedName);
            return row.ToArray();
        }
    }
}
